package com.lzs.esubscribe.utils;

import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@Component
public class FileUtils {
    public List<String> readFileToString(MultipartFile file) throws IOException {
        List<String> res = new ArrayList<>();
        //起手转成字符流
        InputStream is = file.getInputStream();
        InputStreamReader isReader = new InputStreamReader(is, StandardCharsets.UTF_8);
        BufferedReader br = new BufferedReader(isReader);
        //循环逐行读取
        while (br.ready()) {
            res.add(br.readLine());
            // System.out.println(br.readLine());
        }
        //关闭流，讲究
        br.close();
        return res;
    }
}
